package com.atguigu.tingshu.album.rpc;

import com.atguigu.tingshu.album.service.AlbumInfoService;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.vo.album.AlbumStatVo;
import com.atguigu.tingshu.vo.album.TrackListVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: AlbumInfoRpcController
 * Package: com.atguigu.tingshu.album.rpc
 * Description:
 *
 * @Create 2025/1/20 16:43
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/inner/albuminfo")
public class AlbumInfoRpcController {

    @Autowired
    private AlbumInfoService albumInfoService;

    @Autowired
    private TrackInfoService trackInfoService;


    @Autowired
    private BaseCategoryService baseCategoryService;


    @GetMapping("/getAllAlbumInfoIds")
    @Operation(summary = "查询所有专辑id")
    public Result<ArrayList<Long>> getAllAlbumInfoIds() {
        ArrayList<Long> albumInfoIds = albumInfoService.getAllAlbumInfoIds();
        return Result.ok(albumInfoIds);
    }
    @GetMapping("/getAlumInfo/{albumId}")
    @Operation(summary = "根据专辑id查询专辑信息")
    @Parameter(name = "albumId", description = "专辑id", required = true)
    public Result<AlbumInfo> getAlumInfo(@PathVariable("albumId") Long albumId) {
        AlbumInfo albumInfo = albumInfoService.getAlbumInfo(albumId);
        return Result.ok(albumInfo);
    }


    @GetMapping("/getAlbumInfoCategory/{albumId}")
    @Operation(summary = "根据专辑id查询专辑分类信息")
    @Parameter(name = "albumId", description = "专辑id", required = true)
    public Result<BaseCategoryView> getAlbumInfoCategory(@PathVariable("albumId") Long albumId) {
        BaseCategoryView baseCategoryView = albumInfoService.getAlbumInfoCategory(albumId);
        return Result.ok(baseCategoryView);
    }

    @GetMapping("/getAlbumInfoStat/{albumId}")
    @Operation(summary = "根据专辑id查询专辑统计信息")
    @Parameter(name = "albumId", description = "专辑id", required = true)
    Result<AlbumStatVo> getAlbumInfoStat(@PathVariable(value = "albumId") Long albumId) {
        AlbumStatVo albumStatVo = albumInfoService.getAlbumInfoStat(albumId);
        return Result.ok(albumStatVo);
    }

    @GetMapping("/getC1Id7TopBaseCategory3List/{c1Id}")
    @Operation(summary = "根据一级分类id查询7个置顶的三级分类对象")
    @Parameter(name = "c1Id", description = "一级分类id", required = true)
    Result<List<BaseCategory3>> getC1Id7TopBaseCategory3List(@PathVariable(value = "c1Id") Long c1Id) {
        List<BaseCategory3> baseCategory3List = baseCategoryService.getC1Id7TopBaseCategory3List(c1Id);
        return Result.ok(baseCategory3List);
    }

    @GetMapping("/getCategory1IdList")
    @Operation(summary = "获取所有的一级分类id集合")
    Result<List<Long>> getCategory1IdList() {
        List<Long> c1IdList = baseCategoryService.getCategory1IdList();
        return Result.ok(c1IdList);
    }


    @PostMapping("/getTrackInfoList")
    @Operation(summary = "根据声音id集合查询声音信息")
    @Parameter(name = "collectTrackIds", description = "声音id集合", required = true)
    Result<List<TrackListVo>> getTrackInfoList(@RequestBody List<Long> collectTrackIds){
        List<TrackListVo> trackListVoList = albumInfoService.getTrackInfoList(collectTrackIds);
        return Result.ok(trackListVoList);
    }

    @GetMapping("/getTrackInfoById/{trackId}")
    @Operation(summary = "根据声音id查询声音对象")
    @Parameter(name = "trackId", description = "声音id", required = true)
    Result<TrackInfo> getTrackInfoById(@PathVariable(value = "trackId") Long trackId) {
        return Result.ok(trackInfoService.getById(trackId));
    }

    @Operation(summary = "即能把买过的声音查询出来又能把买过的声音过滤掉 返回真正能买的声音")
    @GetMapping("/getPaidTrackAndFilterCanPayTrack/{albumId}/{userId}/{trackCount}/{trackId}")
    @Parameters({
            @Parameter(name = "albumId", description = "专辑id", required = true),
            @Parameter(name = "userId", description = "用户id", required = true),
            @Parameter(name = "trackCount", description = "声音数量", required = true),
            @Parameter(name = "trackId", description = "声音id", required = true)
    })
    public Result getPaidTrackAndFilterCanPayTrack(@PathVariable(value = "albumId") Long albumId,
                                                       @PathVariable(value = "userId") Long userId,
                                                       @PathVariable(value = "trackCount") Integer trackCount,
                                                       @PathVariable(value = "trackId") Long trackId) {
        return trackInfoService.getPaidTrackAndFilterCanPayTrack(albumId, userId, trackCount, trackId);
    }


}
